package com.dao;

import javax.annotation.Resource;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.stereotype.Repository;

import com.beans.AdminInfo;


@Repository
public class AdminDaoImpl implements IadminDao {
	
	@Resource
	SqlSessionFactory sqlSessionFactory; 
	
	 
	public AdminInfo login(AdminInfo user) {
		SqlSession  session=sqlSessionFactory.openSession();
		AdminInfo admin=(AdminInfo) session.selectOne("xxx.login",user);
		session.commit();
		session.close();
		return admin;
	}
	
	
	public int addAdmin(AdminInfo admin) {
		SqlSession  session=sqlSessionFactory.openSession();
		int result=session.insert("xxx.addAdmin",admin);
		session.commit();
		session.close();
		return result;
	}

	public AdminInfo getAdminById(int id) {
		SqlSession  session=sqlSessionFactory.openSession();
		AdminInfo admin = session.selectOne("xxx.getAdminById",id);
		session.close();
		return admin;
	}

	public void delAdmin(int id) {
		SqlSession  session=sqlSessionFactory.openSession();
		session.delete("xxx.delAdminById",id);
		session.commit();
		session.close();
	}

	public int updateAdmin(AdminInfo admin) {
		SqlSession  session=sqlSessionFactory.openSession();
		int result=session.update("xxx.updateAdmin",admin);
		session.commit();
		session.close();
		return result;
	}

}
